package com.asktgapp.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.asktgapp.R;


/**
 * time:2018/1/31
 * Create By ZhaoKai
 * Email: dczk@foxmail.com
 * Description:
 */

@SuppressLint("ValidFragment")
public class YaoQingPJDialog extends DialogFragment implements View.OnClickListener {
    private onResultCallBack onResultCallBack;
    private TextView mCancel, mSure;

    @SuppressLint("ValidFragment")
    public YaoQingPJDialog(onResultCallBack onResultCallBack) {
        this.onResultCallBack = onResultCallBack;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = new Dialog(getContext());
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.dialog_yao_qing_pj);
        mCancel = dialog.findViewById(R.id.tv_cancel);
        mSure = dialog.findViewById(R.id.tv_sure);
        mCancel.setOnClickListener(this);
        mSure.setOnClickListener(this);
        Window window = dialog.getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        WindowManager.LayoutParams params = window.getAttributes();
        WindowManager windowManager = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
        window.setBackgroundDrawableResource(R.drawable.dialog_bg);
        Display display = windowManager.getDefaultDisplay();
        params.width = display.getWidth() * 3 / 5;
        params.gravity = Gravity.CENTER;
        params.windowAnimations = R.style.popwin_anim_style;
        window.setAttributes(params);
        return dialog;
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.tv_cancel:
                dismiss();
                onResultCallBack.onCancel();

                break;
            case R.id.tv_sure:
                dismiss();
                onResultCallBack.onSure();

                break;
        }
    }


    public interface onResultCallBack {
        void onCancel();

        void onSure();
    }
}
